*****************************************************
* 7. COMPARING RESULTS WITH GLOBAL BAROMETER SURVEY *
*****************************************************

***************************************************************
* CONTENT:	(1) Merging selected GBS variables to WVS dataset *
*			(2) Comparing statistics                          *
***************************************æ***********************


* (1) Merging selected GBS variabes to WVS dataset
**************************************************

* Loading GBS dataset

use GBS1.0.dta, clear

* Keeping the variables of interest

keep country_un year rp9 rp4

* Renaming them
rename country_un country
replace country=204 if country==240

rename rp9 E117_gbs
rename rp4 E114_gbs

* Create id variable

egen country_id=group(country year)

* Cleaning outcome variables and creating mean variables

gen E117_gbs_clean=E117_gbs if E117_gbs>0 & E117_gbs<5
bysort country_id: egen E117_mean_gbs=mean(E117_gbs_clean)

gen E114_gbs_clean=E114_gbs if E114_gbs>0 & E114_gbs<5
bysort country_id: egen E114_mean_gbs=mean(E114_gbs_clean)

* Keeping only one observation

bysort country_id: gen group_id=1 if _n==1
keep if group_id==1

* Sorting and saving

sort country year
save GBS_reduced.dta, replace

* Loading humanity dataset

use WPO_world_data_10k_bis.dta, clear

* Creating mean variables

bysort country_id: egen E114_mean_humanity=mean(E114_simulation)
bysort country_id: egen E117_mean_humanity=mean(E117_simulation)

* Keeping only one observation

bysort country_id: gen group_id=1 if _n==1
keep if group_id==1

* Sorting an merging

sort country year
merge 1:1 country year using GBS_reduced.dta, nogen

* Saving

save WPO_humanity_GBS.dta, replace

* (2) Comparing statistics
**************************

* Creating a difference variable

gen diff_E114=E114_mean_humanity-E114_mean_gbs
gen diff_E117=E117_mean_humanity-E117_mean_gbs

* Summary statistics

sum E114_mean_humanity E114_mean_gbs diff_E114 if E114_mean_gbs!=. & E114_mean_humanity!=.
sum E117_mean_humanity E117_mean_gbs diff_E117 if E117_mean_gbs!=. & E117_mean_humanity!=.

* (3) Predictions against real values in the sample
***************************************************

* Loading humanity dataset

use WPO_world_data_10k_bis.dta, clear

* Creating mean variables

bysort country_id: egen E114_mean_humanity=mean(E114_simulation)
bysort country_id: egen E117_mean_humanity=mean(E117_simulation)
bysort country_id: egen D059_mean_humanity=mean(D059_simulation)

* Keeping only one observation

bysort country_id: gen group_id=1 if _n==1
keep if group_id==1

* Sorting and merging with QOG datasets

sort country year
merge 1:1 country year using WPO_QOG_WVS.dta, nogen

* Creating a label identifying the 5 largest countries of the world

gen country2="CN" if country==156
replace country2="IN" if country==356
replace country2="ID" if country==360
replace country2="US" if country==840
replace country2="PK" if country==586

* Plotting scatter plot

scatter E114_mean_humanity E114_mean_wvs, mlabel(country2) mc(gs10) msize(tiny) scheme(s2mono) graphregion(color(white)) ytitle("Mean (humanity)") xtitle("Mean (WVS)") xlabel(1(1)4) ylabel(1(1)4) title("Strong leader")
graph save p1.gph, replace

scatter E117_mean_humanity E117_mean_wvs, mlabel(country2) mc(gs10) msize(tiny) scheme(s2mono) graphregion(color(white)) ytitle("Mean (humanity)") xtitle("Mean (WVS)") xlabel(2(1)4) ylabel(2(1)4) title("Democracy")
graph save p2.gph, replace

scatter D059_mean_humanity D059_mean_wvs, mlabel(country2) mc(gs10) msize(tiny) scheme(s2mono) graphregion(color(white)) ytitle("Mean (humanity)") xtitle("Mean (WVS)") xlabel(1(1)4) ylabel(1(1)4) title("Male leader")
graph save p3.gph, replace

graph combine p1.gph p2.gph p3.gph, xsize(8) row(1) graphregion(color(white))
graph export fit.png, replace
